Fix loading of unencrypted PKCS#8 DER private keys on pre-3.x#190
Draft
toddr-bot wants to merge 1 commit into
Draft
Fix loading of unencrypted PKCS#8 DER private keys on pre-3.x#190toddr-bot wants to merge 1 commit into
toddr-bot wants to merge 1 commit into
Conversation
On pre-3.x (including LibreSSL), _new_private_key_der without a passphrase only tried d2i_RSAPrivateKey_bio, which handles PKCS#1 (traditional RSA) format but fails on PKCS#8 PrivateKeyInfo. Add _load_pkcs8_unenc_der_key helper that uses d2i_PKCS8_PRIV_KEY_INFO_bio + EVP_PKCS82PKEY as a fallback when PKCS#1 parsing fails. On 3.x this path is unused — OSSL_DECODER already handles both formats. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
toddr-bot
added a commit
to toddr-bot/Crypt-OpenSSL-RSA
that referenced
this pull request
May 24, 2026
On pre-3.x, new_private_key() without a passphrase calls d2i_RSAPrivateKey_bio() which only handles PKCS#1 DER format. Unencrypted PKCS#8 DER import is not supported until OpenSSL 3.x (or with the fix in PR cpan-authors#190). Without this skip, the test dies on Debian bullseye (OpenSSL 1.1.1), killing the remaining 6 tests. The encrypted PKCS#8 DER tests still run on pre-3.x because the passphrase code path uses d2i_PKCS8PrivateKey_bio() which handles PKCS#8 correctly. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Fix
new_private_key()to accept unencrypted PKCS#8 DER private keys on pre-3.x OpenSSL (including LibreSSL).Why
On pre-3.x,
_new_private_key_derwithout a passphrase only triedd2i_RSAPrivateKey_bio, which parses PKCS#1 (traditional RSA) DER format. Unencrypted PKCS#8 DER (PrivateKeyInfostructure, as produced byopenssl pkey -outform DER) would fail because the ASN.1 structure differs from PKCS#1RSAPrivateKey.Encrypted PKCS#8 DER already worked (when a passphrase was provided), but the unencrypted variant was silently broken on pre-3.x. On 3.x,
OSSL_DECODERhandles both formats transparently.How
Added
_load_pkcs8_unenc_der_key()helper (placed before the EVP_PKEY→RSA compatibility macros) that usesd2i_PKCS8_PRIV_KEY_INFO_bio()+EVP_PKCS82PKEY()to parse unencrypted PKCS#8 DER and extract the RSA key. The no-passphrase path now tries PKCS#1 first and falls back to unencrypted PKCS#8 on failure.Testing
t/der.t: unencrypted PKCS#8 DER round-trip (load, is_private, public key export, sign/verify)🤖 Generated with Claude Code
Quality Report
Changes: 2 files changed, 57 insertions(+), 1 deletion(-)
Code scan: clean
Tests: passed (OK)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline